package com.joelbitar.switchctrl;

import java.util.ArrayList;

import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.TextView;

public class ServerListAdapter extends ArrayAdapter<Server> {
	private ArrayList<Server> servers;
	private final Context context;
	
	public ServerListAdapter(Context context, int textViewResourceId, ArrayList<Server> servers) {
		super(context, textViewResourceId, servers);

		this.servers = servers;
		this.context = context;
	}

	@Override
    public View getView(int position, View convertView, ViewGroup parent) {
		
		Log.i("getview", "In GetView");
		
            View v = convertView;
            if (v == null) {
                LayoutInflater vi = (LayoutInflater) this.context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                v = vi.inflate(R.layout.settings_servers_row, null);
            }
            
            Server server = this.servers.get(position);
            
            if (server != null) {
            	// Setting all the data
				TextView name = (TextView) v.findViewById(R.id.name);
				
				//v.setTag(1, 1);
				v.setTag(server);
				
				Log.v("serveradapter", "Setting data");
				Log.i("name", server.getName());
				Log.i("id", "" + server.getId());
				
				if(name != null){
				    name.setText(server.getName());
				}
				
            }
            
            return v;
    }
	
	
}
